<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>邮箱测试</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="Author" content="larry" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="/static/admin/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/admin/backstage/css/base.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/admin/common/css/animate.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/admin/backstage/css/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="larry-container larryms-admin">
        <div class="layui-row layui-col-space20">
            <div class="layui-col-xs12 animated fadeInRightBig">
                <section class="larry-panel">
                    <div class="larryms-page-header">
                        <span class="tit">邮箱测试</span>
                    </div>
                    <div class="larryms-page-body">
                        <form class="layui-form">
                            <div class="layui-form-item">
                                <label class="layui-form-label">邮箱地址</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="mail" class="layui-input" value="" required lay-verify="required">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">验证码</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="vcode" class="layui-input">
                                </div>
                                <input type="button" id="btn" class="layui-btn layui-btn-normal" lay-filter="vcode" id="vcode" value="免费获取验证码" onclick="getvcode(this)" name="code" />
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-filter="dologin" lay-submit>立即登录</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
<!-- 加载js文件-->
<script type="text/javascript" src="/static/admin/common/layui/layui.js"></script>
<script>
    //Demo
    var $ , form;
    layui.use(['form','jquery', 'layer'], function(){
        $ = layui.$; //重点处
        form  = layui.form;
        layer = layui.layer;
        //ajax表单提交
        form.on("submit(dologin)", function(data){
            $.ajax({
                type:"POST",
                url:"{:url('admin/demo/vCodeMail')}",
                dataType:"JSON",
                data:data.field,
                success:function(res){
                    if(res.code == '1'){
                        layer.msg(res.msg, {icon: 6});
                        //console.log(data.code);
                    }else{
                        layer.msg(res.msg, {icon: 5});
                    }
                }
            });
            return false;
        })
    });


    var countdown=30;
    function settime(obj) {
        if (countdown == 0) {
            obj.removeAttribute("disabled");
            obj.value="获取验证码";
            countdown = 30;
            return;
        } else {
            obj.setAttribute("disabled", true);
            obj.value="重新发送(" + countdown + ")";
            countdown--;
        }
        setTimeout(function() {
                settime(obj) }
            ,1000)

    }
    function getvcode(obj){
        var mail = $(".layui-form :input[name='mail']").val();
        console.log(mail);
        $.ajax({
            type:"GET",
            url:"{:url('admin/demo/Email')}",
            dataType:"JSON",
            data:{'mail':mail},
            success:function(res){
                if(res.code == '1'){
                    layer.msg(res.msg, {icon: 6});
                    settime(obj);
                    //console.log(data.code);
                }else{
                    layer.msg(res.msg, {icon: 5});
                }

            }
        });
        return false;
    }
</script>
</body>
</html>